package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import service.ExcelService;

@Controller
public class ExcelController {
    @Autowired
    private ExcelService excelService;

    @RequestMapping(value = "/toupload")
    public String toUpload() {
        return "fileUpload";
    }

    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    @ResponseBody
    public String excelUpload(@RequestParam("file") MultipartFile uploadFile) {
        try {
            if (!uploadFile.isEmpty()) {
                System.out.println("到达controller");
                excelService.inputExcel(uploadFile.getInputStream());
            }
            return "success";
            //抛异常则返回异常信息
        } catch (Exception e) {
            e.printStackTrace();
            return e.getMessage();
        }
    }


}
